<?php
/* This file is part of Mirasol CMS
   (C) 2011 by Alban Technologies. Written by Chris Alban Hansen.
   Released under the terms of the GNU General Public License.
   See COPYING in the top level directory of the Mirasol CMS installation. */

include "{$_SERVER['DOCUMENT_ROOT']}/includes/config.php";
include "{$_SERVER['DOCUMENT_ROOT']}/includes/core.php";
include "{$_SERVER['DOCUMENT_ROOT']}/includes/db.php";

if (!isset ($_GET['p']))
{
  $install = 1;
  include "{$_SERVER['DOCUMENT_ROOT']}/includes/install.php";
}

include "{$_SERVER['DOCUMENT_ROOT']}/includes/login.php";

/* Show the login form? */
$showlogin = $login['username'] == "" && $createadmin != 1 ? 1 : 0;

$connection = db_open ();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:php="http://php.net/xsl" xml:lang="en">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <meta name="robots" content="noindex, nofollow" />
    <title>Mirasol CMS</title>

    <script type="text/javascript">
      //<![CDATA[
        if (window != top) top.location.href = location.href;
      //]]>
    </script>
    <script type="text/javascript"> 
      //<![CDATA[
        function externalLinks ()
        {
          if (!document.getElementsByTagName) return;
          var anchors = document.getElementsByTagName ("a");
          for (var i = 0; i < anchors.length; i++)
            {
              var anchor = anchors[i];
              if (anchor.getAttribute ("href") && anchor.getAttribute ("rel") == "external")
                anchor.target = "_blank";
            }
        }
        window.onload = externalLinks;
      //]]>
    </script>
   <script type="text/javascript" src="../scripts/jquery.min.js"></script>
<?php
if ((!isset ($_GET['p']) || $_GET['p'] == "site") && isset ($_GET['pid']))
{
?>
    <script type="text/javascript" src="scripts/tiny_mce/tiny_mce.js"></script>
    <script type="text/javascript">
      //<![CDATA[
        tinyMCE.init ({
          theme : "advanced",
          mode : "exact",
          elements : "htmleditor",
          
          theme_advanced_buttons1 : "undo,redo,|,cut,copy,paste,charmap,|,justifyleft,justifycenter,justifyright,justifyfull,|,visualaid,code",
      		theme_advanced_buttons2 : "bold,italic,underline,strikethrough,|,bullist,numlist,|,link,unlink",
		      theme_advanced_buttons3 : "",
          
          theme_advanced_toolbar_location : "top",
          theme_advanced_toolbar_align : "left",
		      theme_advanced_statusbar_location : "bottom"
        });
      //]]>
    </script>
<?php
}
?>
<?php
if (!isset ($_GET['p']) || $_GET['p'] == "site")
{
?>
    <script type="text/javascript">
      //<![CDATA[
        function delpage (path, pid)
        {
          if (confirm ("You are about to delete:\n\n\t"+path+"\n\nAre you sure?"))
            window.location = "../includes/delpage.php?pid="+pid;
        }
      //]]>
    </script>
<?php
}
?>
<?php
if ($_GET['p'] == "templates" && isset ($_GET['tid']))
{
?>
    <link rel="stylesheet" href="scripts/codemirror/lib/codemirror.css" type="text/css" />
    <script type="text/javascript" src="scripts/codemirror/lib/codemirror.js"></script>
    <script type="text/javascript" src="scripts/codemirror/xmlpure.js"></script>
    <link rel="stylesheet" href="scripts/codemirror/theme/default.css" type="text/css" />
    <style type="text/css">
      .CodeMirror {
        border: 1px solid #aaa;
        background-color: #fff;
      }
    </style>
<?php
}
?>
<?php
if ($_GET['p'] == "templates")
{
?>
    <script type="text/javascript">
      //<![CDATA[
        function deltemplate (name, tid)
        {
          if (confirm ("You are about to delete:\n\n\t"+name+"\n\nAre you sure?"))
            window.location = "../includes/deltemplate.php?tid="+tid;
        }
      //]]>
    </script>
<?php
}
?>
<?php
if ($_GET['p'] == "site" || $_GET['p'] == "templates")
{
?>
		<script type="text/javascript">
		  // <![CDATA[
				function switchtabs (tab)
				{
					if (tab == "tab1")
						{
							document.getElementById ("tab1").style.display = "block";
							document.getElementById ("tab2").style.display = "none";
						}
					else if (tab == "tab2")
						{
							document.getElementById ("tab1").style.display = "none";
							document.getElementById ("tab2").style.display = "block";
						}
				}
			// ]]>
		</script>
<?php
}
?>
    <link rel="icon" href="./favicon.ico" type="image/x-icon" /> 
    <link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./style.css" type="text/css" media="screen" />
  </head>

  <body>
    <div id="menu">
<?php
if ($showlogin == 1)
{
?>
      <ul>
        <li><span><?=$app_name ?> <?=$app_version ?></span></li>
      </ul>
<?php
}
else
{
?>
      <div class="alignright">
        <ul>
          <li><a href="./?p=about">About</a></li>
          <li><a href="./logoff.php">Log off</a></li>
        </ul>
      </div>
      <ul>
        <li><a href="./?p=site">Site</a></li>
        <li><a href="./?p=templates">Templates</a></li>
        <li><a href="#">Styles</a></li>
        <li><a href="#">Files</a></li>
        <li><a href="#">Users</a></li>
        <li><a href="./?p=settings">Settings</a></li>
      </ul>
<?php
}
?>
    </div>
    
    <div id="content">
      <?php
        $loadsubpage = 1;
        
        if ($createadmin == 1)
          include getcurrentpath ()."/createadmin.php";
        else if ($showlogin == 1)
          include getcurrentpath ()."/login.php";
        else if (!isset ($_GET['p']) || $_GET['p'] == "site")
          include getcurrentpath ()."/site.php";
        else if ($_GET['p'] == "about")
          include getcurrentpath ()."/about.php";
        else if ($_GET['p'] == "settings")
          include getcurrentpath ()."/settings.php";
        else if ($_GET['p'] == "templates")
          include getcurrentpath ()."/templates.php";
      ?>
    </div>
    
    <div id="footer">
      <p><?=$app_name?> (Ver. <?=$app_version?>)<br /><?=$app_copyright?><br /><?=$app_license?></p>
    </div>
  </body>
</html>
<?php
db_close ($connection);
?>
